/**
 * 提现密码修改成功
 * @author  Jello
 * @create  2018/10/18 14:08
 * @version 1.0
 * @company 广东蓝聘科技网络有限公司
 **/
var sessionStorage = window.sessionStorage;
var spinner = new Spinner(opts);
var i = 0;
var newWithPwd = ""; //新提现密码
var userid_sign = "";

$(function() {
	userid_sign = sessionStorage.getItem("userid_sign");
	if(!userid_sign){
		userid_sign = sessionStorage.getItem("openid");
	}
	
	var withpwd = sessionStorage.getItem("new_withpwd"); //提现密码

	//数字显示隐藏
	$(".xiaq_tb").click(function() {
		$(".numb_box").slideUp(500);
	});
	$(".mm_box").click(function() {
		$(".numb_box").slideDown(500);
	});

	//删除
	$(".nub_ggg li .zf_del").click(function() {
		if(i > 0) {
			i--
			$(".mm_box li").eq(i).removeClass("mmdd");
			$(".mm_box li").eq(i).attr("secondWithPwd", "");
		}
	});
	//清空
	$(".nub_ggg li .zf_empty").click(function() {
		$(".mm_box li").removeClass("mmdd");
		$(".mm_box li").attr("secondWithPwd", "");
		i = 0;
	});

	//两次提现密码校验
	$(".nub_ggg li .zf_num").click(function() {
		if(i < 6) {
			$(".mm_box li").eq(i).addClass("mmdd");
			$(".mm_box li").eq(i).attr("secondWithPwd", $(this).text());
			i++
			if(i == 6) {
				setTimeout(function() {
					var secondWithPwd = "";
					$(".mm_box li").each(function() {
						secondWithPwd += $(this).attr("secondWithPwd");
					});
					if(secondWithPwd != withpwd) {
						$.myToast("密码不一致,请重新输入");
						$(".mm_box li").removeClass("mmdd");
						$(".mm_box li").attr("secondWithPwd", "");
						i = 0;
						return false;
					} else {
						newWithPwd = secondWithPwd;
						$(".numb_box").hide();
					}
				}, 100);
			};
		}
	});

	//提现密码完成
	$("#complete_btn").click(function() {
		if(i < 6) {
			$.myToast("请输入新的提现密码");
			return false;
		} else {
			//提现密码修改接口上送
			var param = {};
			param.userid_sign = userid_sign;
			param.type = 2;
			param.oldPwd = "";
			param.withdrawPwd = hex_md5(hex_md5(newWithPwd) + salt);
			checkWithdrawPwd(param, function(resultObj) {
				if(resultObj.code == 0 && resultObj.data == 1) {
					$.myToast("密码修改成功");
					setTimeout(function() {
						if(sessionStorage.getItem("wallet_sign") == 001166) {
							window.location.href = "../../wallet.html";
						} else if(sessionStorage.getItem("paycard_sign") == 001177) {
							window.location.href = "../../paycardmanager_grade.html";
						} else {
							window.location.href = "../../app/personal/personal.html";
						}
					}, 500);
				}
			})
		}
	})

})